import { _decorator, Component, Node, SkeletalAnimation } from 'cc';
import { NPCController } from '../Controller/NPCController';
import { GameManager } from '../GameManager';
import { EventManager, IncidentEvent } from '../EventManager';
const { ccclass, property } = _decorator;

@ccclass('DogContriller')
export class DogContriller extends NPCController {
    @property(SkeletalAnimation)
    skeani: SkeletalAnimation = null;
    public Speed: number = 1;
    public _Speed: number = 1;
    protected start(): void {
        this.schedule(() => {
            if (GameManager.Instance.PlayerIsOnDogBox) {
                EventManager.Emit(IncidentEvent.OverTask, 8);
                GameManager.Instance.DogFind();
                if (this.node.getWorldPosition().subtract(GameManager.Instance.PlayerNode.getWorldPosition()).length() < 2) {
                    GameManager.Instance.bulliedbydog();
                }
            }
        }, 1)
    }
    //设置动画状态
    SetAnimation() {
        let animation: string = "idle";
        if (GameManager.Instance.PlayerIsOnDogBox) {
            animation = "Run";
        }

        if (!this.skeani.getState(animation).isPlaying) {
            this.skeani.play(animation);
        }
    }
}


